import matplotlib.pyplot as plt
import numpy as np

# 准备数据
n = 12
x = np.linspace(0, 11, n)

# y11 = np.array([15.00, 14.95, 15.08, 15.15, 15.66,15.00, 14.95, 15.08, 15.15, 15.66,15.00, 14.95])
# y12 = np.array([15.43, 15.42, 15.62, 15.66, 15.43, 15.42, 15.62, 15.66, 15.43, 15.66,15.00, 14.95, 14.95])
y11 = np.array([
1,
0.99,
0.98,
0.97,
0.95,
0.82,
0.61,
0.63,
0.71,
0.71,
0.63,
0.61
])
y12 = np.array([
0.99,
0.95,
0.91,
0.89,
0.79,
0.46,
0.29,
0.32,
0.44,
0.44,
0.4,
0.35
])
# 创建图形和坐标轴对象
fig, axs = plt.subplots(1, 1, figsize=(5, 3))

# 绘制第一个图
axs.plot(x, y11, label='bottom->top', color='steelblue', linestyle='-')
axs.scatter(x, y11, color='steelblue', marker='D', s=20)
axs.set_xticks(x)
# axs.set_xticklabels(['10', '20', '30', '40', '50'])
axs.tick_params(axis='x', colors='black')


axs.plot(x, y12, label='top->bottom', color='chocolate', linestyle='-.')
axs.scatter(x, y12, color='chocolate', marker='o', s=20)


axs.set_ylabel('Similarity', fontsize=12, fontweight='normal')
# axs.set_title('Chest(3)', fontsize=12, fontweight='normal')
axs.grid(True, which='both', color='lightgray', alpha=0.8)

# 设置标签颜色

xtick_labels = axs.get_xticklabels()
for label in xtick_labels:
    label.set_color('black')

# 共用一个图例
legend_handles = []
legend_labels = ['Standard FT', 'Constrained']


for i in range(1):
    legend_handles.append((axs.get_lines()[0], axs.collections[0]))
    legend_handles.append((axs.get_lines()[1], axs.collections[1]))

fig.legend(handles=legend_handles, labels=legend_labels, fontsize=10, loc='upper left', bbox_to_anchor=(0.65, 0.9), ncol=1)

# 调整子图的间距
fig.tight_layout()

plt.subplots_adjust(top=0.95)

# 保存图形
plt.savefig('Main_results/plots/layers_sim.png')
